package com.medusa.aps.business.modules.board.model.input;

import com.medusa.aps.business.common.model.constant.CommonPool;
import com.medusa.aps.business.global.model.exception.GlobalException;
import com.medusa.aps.business.global.model.o.RangeDate;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.experimental.Accessors;

import java.time.temporal.ChronoUnit;

/**
 * <p>车间生产详情多日分页查询参数</p>
 * @author An.Yan
 */
@Data
@Accessors(chain = true)
@Schema(description = "车间生产详情多日分页查询参数")
public class WorkshopProductionDetailMultiQueryParam extends WorkshopProductionDetailBaseQueryParam {

    @Schema(description = "日期范围")
    @NotNull
    private RangeDate dateRange;

    /**
     * 计划开始时间范围
     */
    private RangeDate scheduledStartRange;

    /**
     * 计划结束时间范围
     */
    private RangeDate scheduledEndRange;

    /**
     * 校验参数
     */
    public void validateParam() {
        if (this.dateRange.getStart() == null) {
            throw new GlobalException("开始时间不能为空");
        }
        if (this.dateRange.getEnd() == null) {
            throw new GlobalException("结束时间不能为空");
        }
        if (this.dateRange.getStart().isAfter(this.dateRange.getEnd())) {
            throw new GlobalException("开始时间不能晚于结束时间");
        }
        if (this.dateRange.getStart().until(this.dateRange.getEnd(), ChronoUnit.DAYS) > CommonPool.NUMBER_THIRTY) {
            throw new GlobalException("开始时间和结束时间之间天数差不能超过30天");
        }
    }

}
